<?php

class Amazon {

    private $ID;
    private $ASIN;
    private $category;
    private $flag;
    
    public function getByObj(Amazon $a) {
        $list = array();
        $sql = 'SELECT * FROM caws_amazon 
                WHERE 1 ';

        if(strlen($a->getCategory()) > 0) {
            $sql .= "AND category = '" . $a->getCategory() . "' ";
        }

        if(strlen($a->getFlag()) > 0) {
            $sql .= "AND flag = '". $a->getFlag() . "' ";
        }

        $result = mysql_query($sql);
        $i = 0;
        while($rows = mysql_fetch_array($result)) {
            $list[$i]['ID'] = $rows['ID'];
            $list[$i]['asin'] = $rows['asin'];
            $list[$i]['category'] = $rows['category'];
            $list[$i]['flag'] = $rows['flag'];
            $i++;
        }
        return $list;
    }

    public function updateByASIN($asin) {
        $sql = "UPDATE caws_amazon SET
                flag = 'Y'
                WHERE asin = '" . $asin . "' ";
        mysql_query($sql);
    }



    public function setCategory($category) {
        $this->category = $category;
    }

    public function getCategory() {
        return $this->category;
    }

    public function setFlag($flag) {
        $this->flag = $flag;
    }

    public function getFlag() {
        return $this->flag;
    }
}
?>
